package com.java.springboot.elasticsearch.controller;

import com.java.springboot.elasticsearch.common.CommonResult;
import com.java.springboot.elasticsearch.service.ReadBookPdService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 构建索引
 *
 * @author zhangtengfei
 * @date 2021/9/30 10:38
 */

@RestController
@RequestMapping("/es/book")
public class EsBookIndexController {

    @Resource
    private ReadBookPdService readBookPdService;

    /**
     * ---------------------------------------------------- create ----------------------------------------------------
     * 索引全量重建 - 导入所有数据库中数据到ES
     * 双索引库切换
     *
     * @return
     */
    @PostMapping("/index/all")
    public CommonResult<Boolean> indexAll(@RequestParam String index) {
        return CommonResult.success(readBookPdService.reIndexAll(index));
    }
}
